package com.ruoyi;

import com.ruoyi.langchain4j.assistant.Assistant;
import com.ruoyi.langchain4j.assistant.MemoryChatAssistant;
import com.ruoyi.langchain4j.assistant.SeparateChatAssistant;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @description:
 * @author: lizhihua
 * @date: 2025/6/8
 */
@Slf4j
@SpringBootTest
public class ChatMemoryDemo {

    @Autowired
    private OllamaChatModel ollamaChatModel;

    @Test
    public void test() {
        MessageWindowChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
        Assistant assistant = AiServices
                .builder(Assistant.class)
                .chatModel(ollamaChatModel)
                .chatMemory(chatMemory)
                .build();

        String answer1 = assistant.chat("我叫李华 /no_think");
        log.info("回答1:{}",answer1);
        String answer2 = assistant.chat("我叫什么名字? /no_think");
        log.info("回答2:{}",answer2);

    }

    @Autowired
    private MemoryChatAssistant memoryAssistant;

    @Test
    public void test1() {
        String answer1 = memoryAssistant.chat("我是李四 /no_think");
        log.info("回答1:{}",answer1);
        String answer2 = memoryAssistant.chat("我是谁? /no_think");
        log.info("回答2:{}",answer2);
    }

    @Autowired
    private SeparateChatAssistant separateChatAssistant;

    @Test
    public void test2() {
        String answer1 = separateChatAssistant.chat(1,"我是李四");
        log.info("回答1:{}",answer1);
        String answer2 = separateChatAssistant.chat(1,"我是谁?");
        log.info("回答2:{}",answer2);
        String answer4 = separateChatAssistant.chat(2,"我是谁?");
        log.info("回答4:{}",answer4);
    }

}
